﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SevenInvaders.MENU;

namespace SevenInvaders.MENU
{
    class Button:Sprite
    {
        string subtitle;

        Game1.State goToState;

        Boolean mouseOver;

        Texture2D imagemColisao;

        Menu menu;

        SoundEffect somBotao;
        private Texture2D texture2D;
        private Vector2 vector2;
        private Game1.State state;
        private bool p;
        private Texture2D texture2D_2;
        private SoundEffect soundEffect;
        private string p_2;
        private bool p_3;

        

        public Button(Texture2D texture, Vector2 position, string subtitle, Game1.State goToState,
                        Boolean mouseNaImagem, Texture2D imagemColisao, SoundEffect somBotao)
            : base(texture)
        {
            this.Position = position;
            this.subtitle = subtitle;
            this.goToState = goToState;
            mouseNaImagem = false;
            this.imagemColisao = imagemColisao;
            this.somBotao = somBotao;
            
            
            
        }

        public Button(Texture2D texture, Vector2 position, string subtitle, Game1.State goToState,
                        Boolean mouseNaImagem, Texture2D imagemColisao)
            : base(texture)
        {
            this.Position = position;
            this.subtitle = subtitle;
            this.goToState = goToState;
            mouseNaImagem = false;
            this.imagemColisao = imagemColisao;

        }

        public override void Update(GameTime gameTime)
        {


            //se eu apertei o botao do mouse
            if ((Game1.mouse.LeftButton == ButtonState.Pressed)
                && (Game1.mouse_anterior.LeftButton != ButtonState.Pressed))
            {

                //se eu estou com o mouse dentro da regiao do botao
                if (this.Collision.Contains(Game1.mouse.X, Game1.mouse.Y))
                {
                    Game1.current_state = this.goToState;
                    MediaPlayer.Stop();
                    
                }
            }

            //se ele colocar a seta em cima da imagem só uma vez
            if((this.Collision.Contains(Game1.mouse.X, Game1.mouse.Y)) 
                && (!this.Collision.Contains(Game1.mouse_anterior.X, Game1.mouse_anterior.Y)))
            {
                // somBotao.Play();
            }




            if (this.Collision.Contains(Game1.mouse.X, Game1.mouse.Y))
            {
                mouseOver = true;
            }
            else
            {
                mouseOver = false;
            }
        }

        new public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);

            spriteBatch.DrawString(Game1.arial24, this.subtitle,
                new Vector2(this.PositionX, this.PositionY + this.Texture.Height),
                Color.White);

            if (mouseOver == true)
            {
                spriteBatch.Draw(imagemColisao, new Vector2(this.PositionX, this.PositionY), Color.White);
            }
            else
            {
            }

            

        }
    }
}
